package com.gitee.srurl.sid.domain;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

/**
 * @author zxw
 * @date 2023/4/25 21:17
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class SidData {

    /**
     * 起始年份
     */
    private Long startYear;

    /**
     * 是否允许时钟回拨
     */
    private Boolean allowClockBackwards;

    private Long lastTime;

    private Long lastTimeBorrow;

    private Long sequence;

    private Long sequenceBorrow;

    public static SidData.SidDataBuilder builder() {
        return new SidData.SidDataBuilder();
    }

    @ToString
    public static class SidDataBuilder {

        private Long startYear;
        private Boolean allowClockBackwards;
        private Long lastTime;
        private Long lastTimeBorrow;
        private Long sequence;
        private Long sequenceBorrow;

        private SidDataBuilder() {
        }

        public SidDataBuilder startYear(final Long startYear) {
            this.startYear = startYear;
            return this;
        }

        public SidDataBuilder allowClockBackwards(final Boolean allowClockBackwards) {
            this.allowClockBackwards = allowClockBackwards;
            return this;
        }

        public SidDataBuilder lastTime(final Long lastTime) {
            this.lastTime = lastTime;
            return this;
        }

        public SidDataBuilder lastTimeBorrow(final Long lastTimeBorrow) {
            this.lastTimeBorrow = lastTimeBorrow;
            return this;
        }

        public SidDataBuilder sequence(final Long sequence) {
            this.sequence = sequence;
            return this;
        }

        public SidDataBuilder sequenceBorrow(final Long sequenceBorrow) {
            this.sequenceBorrow = sequenceBorrow;
            return this;
        }

        public SidData build() {
            return new SidData(
                    this.startYear == null ? SidConstant.START_YEAR : this.startYear,
                    this.allowClockBackwards == null ? SidConstant.ALLOW_CLOCK_BACKWARDS : this.allowClockBackwards,
                    this.lastTime == null ? -1 : this.lastTime,
                    this.lastTimeBorrow == null ? -1 : this.lastTimeBorrow,
                    this.sequence == null ? -1 : this.sequence,
                    this.sequenceBorrow == null ? -1 : this.sequenceBorrow
            );
        }
    }
}
